{% extends "base.html" %}

{% block title %}个人资料 - SteHub{% endblock %}

{% block content %}
<div class="row">
    <!-- 左侧菜单 -->
    <div class="col-lg-3">
        <div class="card">
            <div class="card-header">
                <h6 class="mb-0">账户设置</h6>
            </div>
            <div class="list-group list-group-flush">
                <a href="{{ url_for('auth.profile') }}" class="list-group-item list-group-item-action active">
                    <i class="fas fa-user me-2"></i>个人资料
                </a>
                <a href="{{ url_for('auth.change_password') }}" class="list-group-item list-group-item-action">
                    <i class="fas fa-key me-2"></i>修改密码
                </a>
                <a href="{{ url_for('main.dashboard') }}" class="list-group-item list-group-item-action">
                    <i class="fas fa-tachometer-alt me-2"></i>个人仪表板
                </a>
                <a href="{{ url_for('auth.sessions') }}" class="list-group-item list-group-item-action">
                    <i class="fas fa-laptop me-2"></i>登录会话
                </a>
            </div>
        </div>
    </div>

    <!-- 右侧内容 -->
    <div class="col-lg-9">
        <div class="card">
            <div class="card-header">
                <h4 class="mb-0"><i class="fas fa-user me-2"></i>个人资料</h4>
            </div>
            <div class="card-body">
                <form method="POST" action="{{ url_for('auth.profile') }}">
                    <div class="row">
                        <!-- 头像设置 -->
                        <div class="col-md-3 text-center">
                            <div class="mb-3">
                                <img src="{{ current_user.avatar_url or url_for('static', filename='images/default-avatar.png') }}" 
                                     class="rounded-circle avatar-lg" alt="头像"
                                     style="width: 120px; height: 120px; object-fit: cover;">
                                <div class="mt-2">
                                    <input type="url" class="form-control form-control-sm" name="avatar_url" 
                                           value="{{ current_user.avatar_url or '' }}" 
                                           placeholder="头像URL">
                                </div>
                                <small class="text-muted">支持 Gravatar 或外部图片链接</small>
                            </div>
                        </div>

                        <!-- 基本信息 -->
                        <div class="col-md-9">
                            <div class="row">
                                <div class="col-md-6">
                                    <div class="mb-3">
                                        <label for="username" class="form-label">用户名</label>
                                        <input type="text" class="form-control" id="username" name="username" 
                                               value="{{ current_user.username }}" required>
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="mb-3">
                                        <label for="email" class="form-label">邮箱地址</label>
                                        <input type="email" class="form-control" id="email" name="email" 
                                               value="{{ current_user.email }}" required>
                                        {% if not current_user.email_verified %}
                                        <div class="form-text">
                                            <a href="{{ url_for('auth.verify_email') }}" class="text-warning">
                                                <i class="fas fa-exclamation-triangle me-1"></i>邮箱未验证
                                            </a>
                                        </div>
                                        {% endif %}
                                    </div>
                                </div>
                            </div>

                            <div class="mb-3">
                                <label for="bio" class="form-label">个人简介</label>
                                <textarea class="form-control" id="bio" name="bio" rows="3" 
                                          placeholder="介绍一下自己...">{{ current_user.bio or '' }}</textarea>
                                <div class="form-text">最多500个字符</div>
                            </div>

                            <!-- 账户信息 -->
                            <div class="row">
                                <div class="col-md-6">
                                    <div class="card bg-light">
                                        <div class="card-body py-2">
                                            <small class="text-muted">用户ID</small>
                                            <p class="mb-0">{{ current_user.id }}</p>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="card bg-light">
                                        <div class="card-body py-2">
                                            <small class="text-muted">注册时间</small>
                                            <p class="mb-0">{{ current_user.created_at|format_timestamp }}</p>
                                        </div>
                                    </div>
                                </div>
                            </div>

                            <div class="mt-4">
                                <button type="submit" class="btn btn-primary">
                                    <i class="fas fa-save me-2"></i>保存更改
                                </button>
                                <a href="{{ url_for('main.dashboard') }}" class="btn btn-outline-secondary">
                                    取消
                                </a>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>

        <!-- 统计信息 -->
        <div class="row mt-4">
            <div class="col-md-4">
                <div class="card text-center">
                    <div class="card-body">
                        <h3 class="text-primary">{{ current_user.posts|length }}</h3>
                        <p class="text-muted mb-0">发布的帖子</p>
                    </div>
                </div>
            </div>
            <div class="col-md-4">
                <div class="card text-center">
                    <div class="card-body">
                        <h3 class="text-success">{{ current_user.comments|length }}</h3>
                        <p class="text-muted mb-0">发表的评论</p>
                    </div>
                </div>
            </div>
            <div class="col-md-4">
                <div class="card text-center">
                    <div class="card-body">
                        <h3 class="text-info">{{ current_user.likes_received }}</h3>
                        <p class="text-muted mb-0">收到的点赞</p>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}